package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Order;
import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

import java.util.List;

public interface OrderMapper {

    //新增订单数据
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into orders " +
            "(number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark," +
            "phone, address, user_name, consignee, estimated_delivery_time, delivery_status, pack_amount, tableware_number, tableware_status) " +
            "values (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod}," +
            "#{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{userName}, #{consignee}," +
            "#{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})")
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据dishId查询order
     * @param currentId
     * @return
     */
    @Select("select * from orders where user_id=#{userId}")
    List<Order> selectById(Long userId);


    /**
     * 历史订单查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> page(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from  orders where id=#{id}")
    Order getByOrderId(Long id);

    /**
     * 取消订单
     * @param id
     */
    @Update("update orders set status=#{status} where id=#{id}")
    void cancelOrder(long id, Integer status);


   // Page<OrderVO> page2(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    List<Orders> getOrderById(Long id);

    @Select("select * from orders where user_id = #{userId}")
    Page<OrderVO> getOrderByUserId(OrdersPageQueryDTO ordersPageQueryDTO);


    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status = #{status}")
    Integer selectByStatus(Integer toBeConfirmed);
    @Select("Select * from orders where id = #{id}")
    Orders selectById2(Long id);
}
